bl_info = {
    "name": "PropertyUI",
    "author": "会飞的键盘侠",
    "version": (0, 0, 1),
    "blender": (3, 0, 0),
    "location": "3DView->UI",
    "category": "属性投射"
}


import bpy


class PropPanel(bpy.types.Panel):
    bl_label = "PP_PT_UI"
    bl_description = "属性投射面板"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "属性投射"

    def draw(self, context):
        layout = self.layout
        layout.label(text="测试")
        view = context.space_data
        layout.prop(view, "lens", text="Focal Length")

        box = layout.box()
        self.show_obj_prop(box)

        box = layout.box()
        self.show_obj_mat_noise(box)

    def show_obj_prop(self, layout: bpy.types.UILayout):
        ob = bpy.context.object
        if ob is None:
            return
        layout.label(text=ob.name)
        layout.prop(ob, "name")

        row = layout.row()
        row.prop(ob, "location")
        row = layout.row()
        row.prop(ob, "rotation_euler")
        row = layout.row()
        row.prop(ob, "scale")

    def show_obj_mat_noise(self, layout: bpy.types.UILayout):
        ob = bpy.context.object
        if ob is None:
            return
        mat = ob.active_material
        if mat is None:
            return
        node_noise = None
        for node in mat.node_tree.nodes:
            if node.label != "TestLabel":
                continue
            node_noise = node
        col = layout.column(align=True)
        col.prop(node_noise, "noise_dimensions")
        for input in node_noise.inputs:
            input.draw(bpy.context, col, node_noise, text=input.name)


def register():
    bpy.utils.register_class(PropPanel)


def unregister():
    bpy.utils.unregister_class(PropPanel)
